package com.lzdongrui.backend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lzdongrui.backend.domain.dto.EliminateDTO;
import com.lzdongrui.backend.domain.vo.EliminateVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.backend.domain.Eliminate;
import com.lzdongrui.backend.service.IEliminateService;
import com.lzdongrui.common.utils.poi.ExcelUtil;
import com.lzdongrui.common.core.page.TableDataInfo;

/**
 * 销假记录Controller
 * 
 * @author ysl
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/backend/eliminate")
public class EliminateController extends BaseController
{
    @Autowired
    private IEliminateService eliminateService;

    /**
     * 查询销假记录列表
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:list')")
    @GetMapping("/list")
    public TableDataInfo list(EliminateDTO eliminate)
    {
        eliminate.setUserid(getUserId());
        eliminate.setUserDepId(getDeptId());
        startPage();
        List<EliminateVO> list = eliminateService.selectEliminateList(eliminate);
        return getDataTable(list);
    }

    /**
     * 导出销假记录列表
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:export')")
    @Log(title = "销假记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EliminateDTO eliminate)
    {
        List<EliminateVO> list = eliminateService.selectEliminateList(eliminate);
        ExcelUtil<EliminateVO> util = new ExcelUtil<EliminateVO>(EliminateVO.class);
        util.exportExcel(response, list, "销假记录数据");
    }

    /**
     * 获取销假记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eliminateService.selectEliminateById(id));
    }

    /**
     * 新增销假记录
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:add')")
    @Log(title = "销假记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Eliminate eliminate)
    {
        return toAjax(eliminateService.insertEliminate(eliminate));
    }

    /**
     * 修改销假记录
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:edit')")
    @Log(title = "销假记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Eliminate eliminate)
    {
        return toAjax(eliminateService.updateEliminate(eliminate));
    }

    /**
     * 删除销假记录
     */
    @PreAuthorize("@ss.hasPermi('backend:eliminate:remove')")
    @Log(title = "销假记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eliminateService.deleteEliminateByIds(ids));
    }
}
